#include "ReconstructViewer.h"
#include <QVector>
#include <QKinectLib/KinectSensor.h>
#include <SensorUtility/FileSensor.h>
#include <glm/gtx/transform.hpp>

ReconstructViewer::ReconstructViewer (QWidget *parent) : QMainWindow (parent),
		_isOpened (false)
{
	ui.setupUi(this);
}

ReconstructViewer::~ReconstructViewer ()
{

}

void ReconstructViewer::closeEvent (QCloseEvent *)
{
	_isOpened = false;
}

void ReconstructViewer::showEvent (QShowEvent *)
{
	if (!_isOpened)
		openEvent ();
}

void ReconstructViewer::openEvent ()
{
	_isOpened = true;
	QString extFiles[] = {
		"../Data/0.ext",
		"../Data/1.ext",
		"../Data/2.ext",
	};
	QVector< Sensor* > sensorPtrs;
	for (int i = 0; i < 1; ++i) {
		sensorPtrs.push_back (new FileSensor (QString ("Kinect %1").arg (i),
				QString ("../Data/07.krec").arg (i),
// 				NUI_IMAGE_TYPE_DEPTH, NUI_IMAGE_RESOLUTION_640x480,
// 				NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480,
				QString ("../Data/Intrinsic/try%1.int").arg (i), extFiles[i]));
//		sensorPtrs[i]->setInvProjMat (QString ("../Data/camera%1.Pmat.cal").arg (i));
	}
	ui.pMainScene->initialize (sensorPtrs);
	for (int i = 0; i < sensorPtrs.size (); ++i)
		sensorPtrs[i]->start ();
// 	ui.pMainScene->initialize ("../Data/0.vertices");
}